package com.lyrcsoft.springmvc.init;

import com.lyrcsoft.springmvc.Start;
import com.lyrcsoft.springmvc.servlet.DispatcherServlet;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import java.util.Set;

/**
 * SPI机制
 *
 * @author fujc-dev@qq.com
 * @version 1.0
 */
public class MyInit implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
        // 打开IOC扫描
        AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(Start.class);

        DispatcherServlet servlet = new DispatcherServlet(ac);
        ServletRegistration.Dynamic dy = ctx.addServlet("app", servlet);
        dy.setLoadOnStartup(1);

    }
}
